<template>
	<view class="padding-b160" :key="refreshKey">
		<view class="my-wallet">
			<view class="my-account-assets">
				<view class="title">
					我的账户总资产
				</view>
				<view class="my-account-assets__content">
					<view class="rmb-symbol">USDT</view>
					<view class="assets-total">
						{{totalAsset}}
					</view>
					<button class="withdraw-btn" @click="gotoPage('../withdraw/withdraw')">立即提现</button>
				</view>
			</view>
			<view class="line"></view>
			<view class="my-assets-detail">
				<view class="title">
					我的资产明细
				</view>
				<view class="gold-border animate__shakeX" style="animation-duration: 2s;"></view>
				<view class="detail-card animate__shakeX" style="animation-duration: 2s;">
					<view class="font">
						累计已提现
					</view>
					<view class="my-assets-detail__content">
						<view class="rmb-symbol">$</view>
						<view class="assets-total">
							{{totalWithdrawAmount}}
						</view>
					</view>
					<!-- <view class="detail-card__footer">
						<view class="footer-font" style="margin-right: 8rpx;">
							累计已提现
						</view>
						<view class="footer-num">
							${{totalWithdrawAmount}}
						</view>
					</view> -->
				</view>
				<view class="blue-border animate__shakeY" style="animation-duration: 2s;"></view>
				<view class="detail-card animate__shakeY" style="animation-duration: 2s;">
					<view class="font">
						累计已投资
					</view>
					<view class="my-assets-detail__content">
						<view class="rmb-symbol">$</view>
						<view class="assets-total">
							${{totalFinancialAmount}}
						</view>
					</view>
					<!-- <view class="detail-card__footer">
						<view class="footer-font" style="margin-right: 8rpx;">
							累计已投资
						</view>
						<view class="footer-num">
							${{totalFinancialAmount}}
						</view>
					</view> -->
				</view>
			</view>
			<view class="my-assets-records">
				<view class="title">
					15天内资产变动记录明细
				</view>
				<view class="record-detail animate__fadeInUp" style="animation-duration: 2s;">
					<view class="record-item" v-for="record in balanceChangeLogs">
						<view class="header">
							<view class="header-title">
								{{record.changeTypeName}}
							</view>
							<view class="header-num gold-font">
								{{record.balanceChange < 0 ? '-' : '+'}}{{moneyFormat(Math.abs(record.balanceChange))}}
							</view>
						</view>
						<view class="footer">
							<view class="date">
								{{record.changeTime}}
							</view>
							<view class="total-conter">
								<view class="text">
									余额
								</view>
								<view class="num">
									{{moneyFormat(record.balanceAfter)}}
								</view>
								<view class="yuan">
									USDT
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="fixed-bottom">
				<view class="fixed-bottom-inner">
					<button class="submit" @click="gotoPage('../recharge/recharge')">账户充值</button>
				</view>
			</view>
		</view>

	</view>

</template>

<script>
	import common from '@/common/common'
	export default {
		data() {
			return {
				accountInfo: '',
				balanceChangeLogs: [],
				totalFinancialAmount: '',
				totalWithdrawAmount: '',
				refreshKey:0
			}
		},
		computed: {
			totalAsset: function() {
				var totalAsset = 0;
				if (this.accountInfo === null || this.accountInfo === '') {
					return '';
				}
				return this.moneyFormat(this.accountInfo.balance);
			}
		},
		onLoad() {
			this.getMemberInfo();
			this.findBalanceChangeLog();
			this.findMyTotalFinancialAmount();
			this.findMyTotalWithdrawAmount();
		},
		onShow(){
			this.refreshKey += 1;
		},
		methods: {
			
			findMyTotalFinancialAmount() {
				var that = this;
				uni.$uv.http.get('/buyInRecord/findMyTotalFinancialAmount').then(res => {
					that.totalFinancialAmount = res.data;
				});
			},
			
			findMyTotalWithdrawAmount() {
				var that = this;
				uni.$uv.http.get('/memberWithdraw/findMyTotalWithdrawAmount').then(res => {
					that.totalWithdrawAmount = res.data;
				});
			},
			
			findBalanceChangeLog() {
				var that = this;
				var queryParam = {
					pageSize: 100,
					pageNum: 1,
				};
				uni.$uv.http.get('/memberBalanceChangeLog/findByPage', {
					params: queryParam
				}).then(res => {
					that.balanceChangeLogs = res.data.content;
				});
			},
			
			moneyFormat(money) {
				return common.moneyFormat(money);
			},

			getMemberInfo() {
				var that = this;
				uni.$uv.http.get('/member/getMemberInfo').then(res => {
					that.accountInfo = res.data;
				});
			},

			gotoPage(path) {
				uni.navigateTo({
					url: path
				});
			}

		}
	}
</script>

<style scoped lang="less">
page {
	height: auto !important;
	background: url('/static/img/my_bg.png') no-repeat;
	background-size: 100% 100%;
	background-color: #FFFFFF;
}
	.padding-b160 {
		// background: #f1f2f6;
		// height: calc(100% - 160rpx);
		padding-bottom: 0;

		.my-wallet {
			padding: 32rpx;

			.gold-font {
				color: #E4D494;
			}

			.my-account-assets {
				&__content {
					display: flex;
					align-items: center;

					.assets-total {
						font-family: DIN Next LT Pro, DIN Next LT Pro;
						font-weight: 500;
						line-height: 60rpx;
						font-size: 60rpx;
						margin-top: 4rpx;
						flex: 1;
					}

					.withdraw-btn {
						background: #F8F3D3;
						border-radius: 38rpx;
						font-weight: 400;
						font-size: 24rpx;
						color: hwb(24 30% 13%);
						line-height: 24rpx;
						letter-spacing: 1px;
						padding: 16rpx 0;
						width: 168rpx;
						margin: 0;
						float: right;
					}
				}
			}

			.my-assets-detail {
				margin-top: 60rpx;

				&__content {
					display: flex;
					align-items: center;
				}

				.detail-card {
					padding: 32rpx;
					background: #FFF;

					.font {
						font-weight: 400;
						font-size: 24rpx;
						color: #000;
						line-height: 24rpx;
						margin-bottom: 52rpx;
					}

					.rmb-symbol {
						font-size: 24rpx;
						margin-top: 0;
					}

					.assets-total {
						font-family: DIN Next LT Pro, DIN Next LT Pro;
						font-weight: 500;
						font-size: 44rpx;
						color: #000;
						line-height: 44rpx;
					}

					&__footer {
						font-family: SF Pro Text, SF Pro Text;
						display: flex;
						align-items: center;
						font-weight: 400;
						font-size: 20rpx;
						color: #000;
						margin-top: 32rpx;
					}
				}

				.gold-border {
					height: 18rpx;
					background: linear-gradient(90deg, #FFF9C3 0%, #FFB637 100%);
				}

				.blue-border {
					margin-top: 32rpx;
					height: 18rpx;
					background: linear-gradient(90deg, #1F3798 0%, #5B1F98 100%);
				}
			}

			.my-assets-records {
				margin-top: 60rpx;

				.record-detail {
					padding: 40rpx;
					background: #FFF;
					border-radius: 28rpx;

					.record-item {
						display: flex;
						flex-direction: column;
						border-bottom: 2rpx solid rgba(255, 255, 255, 0.1);
						padding: 40rpx 0;

						.header,
						.footer {
							display: flex;
							align-items: center;
							justify-content: space-between;
						}

						.header {
							margin-bottom: 20rpx;
						}

						.footer {
							font-family: SF Pro Text, SF Pro Text;
							font-weight: 400;
							font-size: 24rpx;
							color: hwb(240 44% 52%);
							line-height: 24rpx;
						}

						.header-title {
							font-weight: 600;
							font-size: 28rpx;
							color: #000;
							line-height: 28rpx;
							letter-spacing: 1px;
						}

						.header-num {
							font-family: DIN Next LT Pro, DIN Next LT Pro;
							font-weight: 500;
							font-size: 32rpx;
							line-height: 32rpx;
						}

						.total-conter {
							display: flex;
							align-items: center;

							.num {
								padding: 0 8rpx;
							}
						}
					}

					.record-item:first-child {
						padding-top: 0;
					}

					.record-item:last-child {
						border: none;
						padding-bottom: 0;
					}
				}
			}

			.line {
				height: 1rpx;
				background: #D1D1D3;
				border-radius: 0rpx 0rpx 0rpx 0rpx;
				margin-top: 20rpx;
			}

			.title {
				font-weight: 400;
				font-size: 28rpx;
				color: #000;
				line-height: 24rpx;
				margin-bottom: 32rpx;
			}

			.rmb-symbol {

				font-weight: 600;
				font-size: 28rpx;
				color: #000;
				line-height: 28rpx;
				padding-right: 8rpx;
				margin-top: 8rpx;
			}
		}

		.submit {
			// background: linear-gradient(to right, rgb(32, 160, 214), rgb(19, 123, 189));
			background: #FEE19E;
			// color: #fff;
			// border: 0px;
			border-radius: 50rpx;
			height: 100rpx;
			// width:100%;
			// display: block;
			// margin: 0px auto;
			line-height: 100rpx;
			// padding: 0px;
			// box-shadow: 5px 5px 5px rgba(226, 242, 250, 1);
			font-weight: 600;
			font-size: 32rpx;
			color: #0B1327;
			letter-spacing: 1px;
			text-align: center;

			&::after {
				border: 0px solid #fff;
			}
		}

		.fixed-bottom-inner {
			margin-top: 40rpx;
			padding: 0;
			padding: 0 32rpx;
			// padding: 0px 40rpx;
		}
	}
</style>